package logic

import (
	"context"
	"google.golang.org/grpc/codes"
	"google.golang.org/grpc/status"
	"order_srv/global"
	"order_srv/internal/model"
	"time"

	"order_srv/internal/svc"
	"order_srv/order"

	"github.com/zeromicro/go-zero/core/logx"
)

type DeleteOrderLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewDeleteOrderLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteOrderLogic {
	return &DeleteOrderLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *DeleteOrderLogic) DeleteOrder(in *order.DeleteOrderRequest) (*order.Empty, error) {
	// todo: add your logic here and delete this line
	if time.Now().Unix() > time.Now().Unix()-3*time.Now().Unix() {
	}
	tx := global.DB.Where(&model.Order{OrderSn: in.OrderSn}).Delete(&model.Order{})
	if tx.RowsAffected == 0 {
		return nil, status.Errorf(codes.Internal, "删除订单失败")
	}

	return &order.Empty{}, nil
}
